//
//  CYMessageNotificationTableViewCell.m
//  cyydt
//
//  Created by chu on 2019/1/21.
//  Copyright © 2019 chu. All rights reserved.
//

#import "CYMessageNotificationTableViewCell.h"

@implementation CYMessageNotificationTableViewCell

+ (instancetype)initWithTableView:(UITableView *)tableView Identifier:(NSString *)identifier{
    CYMessageNotificationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[NSBundle mainBundle] loadNibNamed:@"CYMessageNotificationTableViewCell" owner:self options:nil][0];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.vipImageView.hidden = YES;
    
    self.headImageView.layer.cornerRadius = self.headImageView.frame.size.height / 2;
    self.headImageView.layer.masksToBounds = YES;
    
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.headImageView addGestureRecognizer:tap];
    [self.headImageView setUserInteractionEnabled:YES];
}

- (void)tapAction:(UITapGestureRecognizer *)tap{
    //关注
    CYGeRenZhuYeViewController *zhuye = [[CYGeRenZhuYeViewController alloc] init];
    zhuye.userId = self.model.fromUserid;
    [[AppDelegate sharedAppDelegate] pushViewController:zhuye];
}

//catId 1=>系统消息(回答消息) 2=>点赞消息 3=>收藏消息 4=>关注消息 5=>审核消息 6=>评论消息 7=>回复消息
//type 类型：4=>问答 7=>新闻 3=>项目 28=>视频
//status 状态 1=》正常(未查看) 2=>已查看 3=》删除

- (void)setModel:(CYMessageNotifiModel *)model{
    _model = model;
    self.bofangImageView.hidden = YES;

    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.fromUserHeadimg] placeholderImage:[UIImage imageWithColor:[UIColor lightGrayColor] Size:self.headImageView.frame.size]];
//    NSString *content = @"";
//    if ([model.type isEqualToString:@"4"]) {
//        content = @"提问";
//    }else if ([model.type isEqualToString:@"7"]){
//        content = @"文章";
//    }else if ([model.type isEqualToString:@"3"]){
//        content = @"项目";
//    }else if ([model.type isEqualToString:@"28"]){
//        content = @"视频";
//    }
    self.fenleiLabel.text = [NSString stringWithFormat:@"%@",model.message];
    self.nicknameLabel.text = model.fromUserNickname;
    self.timeLabel.text = model.createdAt;
    self.contentLabel.text = @"";
    
    if ([model.cateId integerValue] == 4) {
        self.bottomViewHeightConstraint.constant = 0;
        self.bottomViewMarginTopConstraint.constant = 0;
        self.contentLabelMarginTopConstraint.constant = 0;
        self.contentLabel.hidden = YES;
        self.bottomView.hidden = YES;
    }else if ([model.cateId integerValue] == 5){
        self.bottomViewHeightConstraint.constant = 0;
        self.bottomViewMarginTopConstraint.constant = 0;
        self.bottomView.hidden = YES;
        self.fenleiLabel.text = @"审核被驳回";
        self.contentLabel.text = model.message;
    }else if ([model.cateId integerValue] == 2){
        //收藏
        self.bottomViewHeightConstraint.constant = 50;
        self.bottomViewMarginTopConstraint.constant = 15;
        self.bottomView.hidden = NO;
        self.contentLabelMarginTopConstraint.constant = 0;
        self.contentLabel.hidden = YES;
        self.bottomContentLabel.text = [[Tool sharedInstance] delHTMLBiqoQianWithHtml:model.articleTitle];
        if ([model.type isEqualToString:@"28"]) {
            //视频
            self.bottomView.hidden = NO;
            self.bottomImageViewWidthConstraint.constant = 50;
            [self.bottomImageView sd_setImageWithURL:[NSURL URLWithString:model.articleResource] placeholderImage:[UIImage imageNamed:@"wd_gezl_lj"]];
        }else if ([model.type isEqualToString:@"7"]){
            if (model.articleResource) {
                self.bottomImageViewWidthConstraint.constant = 50;
                [self.bottomImageView sd_setImageWithURL:[NSURL URLWithString:model.articleResource] placeholderImage:[UIImage imageNamed:@"wd_gezl_lj"]];
            }else{
                self.bottomImageViewWidthConstraint.constant = 0;
            }
        }else{
            self.bottomImageViewWidthConstraint.constant = 0;
        }
    }else if ([model.cateId integerValue] == 3){
        //点赞
        self.bottomViewHeightConstraint.constant = 50;
        self.bottomViewMarginTopConstraint.constant = 15;
        self.bottomView.hidden = NO;
        self.contentLabelMarginTopConstraint.constant = 0;
        self.contentLabel.hidden = YES;
        self.bottomContentLabel.text = [[Tool sharedInstance] delHTMLBiqoQianWithHtml:model.articleTitle];
        if ([model.type isEqualToString:@"28"]) {
            //视频
            self.bottomView.hidden = NO;
            self.bottomImageViewWidthConstraint.constant = 50;
            [self.bottomImageView sd_setImageWithURL:[NSURL URLWithString:model.articleResource] placeholderImage:[UIImage imageNamed:@"wd_gezl_lj"]];
        }else if ([model.type isEqualToString:@"7"]){
            if (model.articleResource) {
                self.bottomImageViewWidthConstraint.constant = 50;
                [self.bottomImageView sd_setImageWithURL:[NSURL URLWithString:model.articleResource] placeholderImage:[UIImage imageNamed:@"wd_gezl_lj"]];
            }else{
                self.bottomImageViewWidthConstraint.constant = 0;
            }
        }else{
            self.bottomImageViewWidthConstraint.constant = 0;
        }
    }else if ([model.cateId integerValue] == 6 || [model.cateId integerValue] == 7){
        //评论或回复
        self.bottomViewHeightConstraint.constant = 50;
        self.bottomViewMarginTopConstraint.constant = 15;
        self.bottomView.hidden = NO;
        self.contentLabelMarginTopConstraint.constant = 15;
        self.contentLabel.hidden = NO;

        self.contentLabel.text = model.replyContent;

        self.bottomContentLabel.text = [[Tool sharedInstance] delHTMLBiqoQianWithHtml:model.articleTitle];;
        if ([model.type isEqualToString:@"28"]) {
            //视频
            self.bottomView.hidden = NO;
            self.bottomImageViewWidthConstraint.constant = 50;
            [self.bottomImageView sd_setImageWithURL:[NSURL URLWithString:model.articleResource] placeholderImage:[UIImage imageNamed:@"wd_gezl_lj"]];
        }else if ([model.type isEqualToString:@"7"]){
            if (model.articleResource) {
                self.bottomImageViewWidthConstraint.constant = 50;
                [self.bottomImageView sd_setImageWithURL:[NSURL URLWithString:model.articleResource] placeholderImage:[UIImage imageNamed:@"wd_gezl_lj"]];
            }else{
                self.bottomImageViewWidthConstraint.constant = 0;
            }
        }else{
            self.bottomImageViewWidthConstraint.constant = 0;
        }
    }else if ([model.cateId integerValue] == 8){
        self.bottomViewHeightConstraint.constant = 50;
        self.bottomViewMarginTopConstraint.constant = 15;
        self.bottomView.hidden = NO;
        self.contentLabelMarginTopConstraint.constant = 15;
        self.contentLabel.hidden = NO;
        
        self.contentLabel.text = [[Tool sharedInstance] delHTMLBiqoQianWithHtml:model.replyContent];
        
        self.bottomContentLabel.text = [[Tool sharedInstance] delHTMLBiqoQianWithHtml:model.articleTitle];;
        if ([model.type isEqualToString:@"28"]) {
            //视频
            self.bottomView.hidden = NO;
            self.bottomImageViewWidthConstraint.constant = 50;
            [self.bottomImageView sd_setImageWithURL:[NSURL URLWithString:model.articleResource] placeholderImage:[UIImage imageNamed:@"wd_gezl_lj"]];
        }else if ([model.type isEqualToString:@"7"]){
            if (model.articleResource) {
                self.bottomImageViewWidthConstraint.constant = 50;
                [self.bottomImageView sd_setImageWithURL:[NSURL URLWithString:model.articleResource] placeholderImage:[UIImage imageNamed:@"wd_gezl_lj"]];
            }else{
                self.bottomImageViewWidthConstraint.constant = 0;
            }
        }else{
            self.bottomImageViewWidthConstraint.constant = 0;
        }
    }
    
    self.cellHeight = CGRectGetMaxY(self.bottomView.frame) + 15;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
